package com.nulldev.util.languages.json.uniapi;

import com.nulldev.util.JVM.Arguments;
import com.nulldev.util.JVM.Arguments.ParsedArguments;
import com.nulldev.util.JVM.arguments.ArgumentWithValue;

public enum JSONAPI {
	@Deprecated
	/**
	 * Removed in 3.0.1, replaced with V2.
	 */
	V1("v1"),
	V2("v2"),
	FAST("fast")

	;

	public final String id;

	private JSONAPI(final String id) {
		this.id = id;
	}

	public static final String ARG = "--UniJsonValue.api";
	public static final JSONAPI defaultAPI = V2;
	public static final ArgumentWithValue<String> ARGUMENT = new ArgumentWithValue.StringArgument(ARG, "Tells the Universal JSON API to use what framework.",
			"v2, fast", true);

	public static JSONAPI get() {
		final ParsedArguments pa = Arguments.get();
		if (pa != null && pa.has(ARG)) {
			final String c = pa.getValue(ARG);
			for (final JSONAPI v : values()) {
				if (v.id.equalsIgnoreCase(c)) {
					return v;
				}
			}
			return defaultAPI;
		} else {
			if (Arguments.hasArgument("--JSONAPI.fast", "-JSONAPI.fast"))
				return FAST;
			if (Arguments.hasArgument("--JSONAPI.v2", "-JSONAPI.v2"))
				return V2;
			return defaultAPI;
		}
	}
}
